package com.fs.sw.pojo;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.Past;
import java.util.Date;
import java.util.List;
import java.util.Set;

@NamedEntityGraph(name = "users.countrys", attributeNodes = {@NamedAttributeNode("countrys")})
@Entity
@Table(name="t_users")
public class Users {

	public interface  UserView{};
	public interface  UserDetailView extends UserView{};

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id")
	private Integer id;
	
	@Column(name="name")
	private String name;
	
	@Column(name="age")
	private Integer age;
	
	@Column(name="address")
	private String address;

	@Past
	private Date validDatetime;

	@ManyToOne(cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)
	@JoinColumn(name="roles_id")
//	@JsonIgnoreProperties(ignoreUnknown = true, value = {"matDsCheckEntity"})
	private Roles roles;

	@OneToMany(mappedBy="users", fetch = FetchType.LAZY)
	private Set<Country> countrys;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Set<Country> getCountrys() {
		return countrys;
	}

	public void setCountrys(Set<Country> countrys) {
		this.countrys = countrys;
	}

	@Override
	public String toString() {
		return "Users [id=" + id + ", name=" + name + ", age=" + age + ", address=" + address + "]";
	}

//	@JsonBackReference
//	@JSONField(serialize = false)
	public Roles getRoles() {
		return roles;
	}
//	@JsonManagedReference
	public void setRoles(Roles roles) {
		this.roles = roles;
	}


	public Date getValidDatetime() {
		return validDatetime;
	}

	public void setValidDatetime(Date validDatetime) {
		this.validDatetime = validDatetime;
	}
}
